import {Component, OnInit} from '@angular/core';
import {_HttpClient} from '@delon/theme';
import {VideoService} from '../video.service';
import {ActivatedRoute} from '@angular/router';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import {Videotab} from '../videotab';
import {Location} from '@angular/common';

@Component({
    selector: 'app-videotabadd',
    templateUrl: './videotabadd.component.html',
})
export class VideotabaddComponent implements OnInit {

    videotab: Videotab = {};
    layForm: FormGroup;

    constructor(
        private vidoeService: VideoService,
        private activityRouter: ActivatedRoute,
        private fb: FormBuilder,
        private location: Location,
    ) {
    }

    ngOnInit() {
        this.layForm = this.fb.group({
            title: ['', Validators.required],
            count: ['', Validators.required],
        });

        const id = this.activityRouter.snapshot.paramMap.get('id');
        if (id) {
            this.vidoeService.getlay(+id).subscribe(res => {
                this.videotab = res;
                this.layForm.patchValue({
                    title: this.videotab.title,
                    count: this.videotab.count,
                })
                ;
            });
        }
    }

    save() {
        const res = this.layForm.value;
        this.videotab.title = res['title'];
        this.videotab.count = res['count'];
        this.vidoeService.addlay(this.videotab).subscribe(res => {
            this.location.back();
        }, error1 => {

        });
    }

}
